﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>btable</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/css/btable.css" />
    <script src="/static/js/inout/jquery-1.8.2.min.js"></script>
</head>

<body style=" background-color: gainsboro;">
    <div style="margin:0px; background-color: white; margin:0 10px;">
        <blockquote class="layui-elem-quote" style="height: 31px;">
            <button type="button" class="layui-btn layui-btn-small" onclick="addopend();" id="add"><i class="fa fa-plus" aria-hidden="true"></i> 添加</button>
            <form class="layui-form" style="float:right;" action="/admin/lottery/seleclit" method="post">
                <div class="layui-form-item" style="margin:0;">
                    <label class="layui-form-label">搜索</label>
                    <div class="layui-input-inline" style="width: 220px;">
                        <input type="text" name="title" placeholder="输入彩票名字" value="" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux" style="padding:0;">
                        <button lay-filter="search" class="layui-btn" lay-submit type="submit"><i class="fa fa-search" aria-hidden="true"></i> 查询</button>
                    </div>
                </div>
            </form>
        </blockquote>
        <div id="content" style="width: 100%;height: 533px;"></div>
        <div id="demo7"></div>
    </div>

    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
    <script>
        layui.config({
            base: '/static/js/',
            v: new Date().getTime()
        }).use(['btable', 'form','paging'], function () {
            var btable = layui.btable(),
                $ = layui.jquery,
                layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
                layer = layui.layer,//获取当前窗口的layer对象;
                form = layui.form();

            btable.set({
                openWait: true,//开启等待框
                elem: '#content',
                url: '/admin/lottery/seleclit', //数据源地址
                pageSize: 10,
                params: {
                    t: new Date().getTime() //额外的请求参数
                },
                columns: [{ //配置数据列
                    fieldName: '彩票名称', //显示名称
                    field: 'title', //字段名
                    sortable: true //是否显示排序
                },{
                    fieldName: '状态',
                    field: 'status',
                    sortable: true
                },{
                    fieldName: '创建时间',
                    field: 'addTime',
                    sortable: true
                },{
                    fieldName: '修改时间',
                    field: 'updateTime',
                    format: function (id, obj) {
                        //id
                        //行数据对象
                        //返回值：格式化的纯文本或html文本
                        return obj.sign;
                    }
                },{
                    fieldName: '操作',
                    field: 'id',
                    format: function (val,obj) {
                        var po = '';
                        if(obj.enable==1){
                            po="禁用";
                        }else{
                            po="启用";
                        }
                        var html = '<input type="button" value="修改" id="edit" data-action="edit" data-title="'+obj.title+'" data-id="'+val+'" class="layui-btn layui-btn-mini" />' +
                                '<input type="button" data-action="enable" data-id="'+val+'" data-bd="'+obj.enable+'" class="layui-btn layui-btn-normal layui-btn-mini ble polty" value="'+po+'" onclick="defa(this);"/>' +
                                '<input type="button" value="删除" data-action="del" data-id="'+val+'" class="layui-btn layui-btn-mini layui-btn-danger del" name="del" />';
                        return html;
                    }
                }],
                even: true,//隔行变色
                field: 'id', //主键ID
                //skin: 'row',
                checkbox: false,//是否显示多选框
                paged: true, //是否显示分页
                singleSelect: false, //只允许选择一行，checkbox为true生效
                onSuccess: function ($elem) { //$elem当前窗口的jq对象
                    $elem.children('tr').each(function () {
                        $(this).children('td:last-child').children('input').each(function () {
                            var $that = $(this);
                            var action = $that.data('action');
                            var id = $that.data('id');
                            var title = $that.data('title');
                            var curl = $that.data('bd');
                            $that.on('click', function () {
                                switch (action) {
                                    case 'edit':
                                        window.location.href="/admin/lottery/edit?id="+id;
                                        break;
                                    case 'del': //删除
                                        //询问框
                                        layer.confirm('确定要删除？', {
                                            btn: ['确定','取消'] //按钮
                                        }, function(){
                                            var claid = $that.attr('data-id');
                                            $.ajax({
                                                type:"post",
                                                dataType: "json",
                                                url: "/admin/lottery/del",
                                                data:{
                                                    claid:claid
                                                },
                                                success:function(res){
                                                    if(res.status==0){
                                                        layer.msg(res.msg,{icon: 1});
                                                        setTimeout('location.href="/admin/lottery/index"',1000);
                                                    }else{
                                                        layer.msg(res.msg,{icon: 1});
                                                    }
                                                }
                                            });
                                        }, function(){

                                        });
                                        break;
                                }
                            });
                        });
                    });
                }
            });

            btable.render();
            //监听搜索表单的提交事件
            form.on('submit(search)', function (data) {
                btable.get(data.field);
                return false;
            });
            $(window).on('resize', function (e) {
                var $that = $(this);
                $('#content').height($that.height() - 92);
            }).resize();
        });
        //上面那个是页面渲染完就添加的
        //这个是点击之后才添加的。
        function addopend(){
            window.location.href="/admin/lottery/addproble";
        }
        function defa(_this) {
            var m = $(_this).attr("data-bd")==1?'您是否要禁用该彩种?':'您是否要启用该彩种?';
            layer.confirm(m,{
                btn: ['确定','取消'] //按钮
            }, function(){
                var id = $(_this).attr("data-id");
                $.ajax({
                    type:"post",
                    dataType: "json",
                    url: "/admin/lottery/jinyong",
                    data:{
                        id:id
                    },
                    success:function(res){
                        if(res.status==0){
                            layer.msg(res.msg);
                            setTimeout('location.href="/admin/lottery/index"',1000);
                        }else{
                            layer.msg(res.msg);
                        }
                    }
                });
            }, function(){
            });
        }
    </script>
</body>

</html>